package com.example.basic.demos.common.response;

import com.example.basic.demos.exception.ErrorEnum;
import lombok.Data;

@Data
public class CommonResult<T> {

    private Long code;

    private String msg;

    private T data;


    public static <T> CommonResult<T> success(T data) {
        CommonResult<T> res = new CommonResult<T>();
        res.setData(data);
        res.setCode(ErrorEnum.SUCCESS.getCode());
        res.setMsg(ErrorEnum.SUCCESS.getMsg());
        return res;
    }

    public static <T> CommonResult<T> error(ErrorEnum errorEnum) {
        CommonResult<T> res = new CommonResult<T>();
        res.setCode(errorEnum.getCode());
        res.setMsg(errorEnum.getMsg());
        res.setData(null);
        return res;
    }
}
